// pages/check/shopping/list/list.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		http: getApp().globalData.map,
		state: false,
		remake: '',
		address: '',
		name: '',
		mobile: ''
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		wx.getStorage({
			key: 'uid',
			success: (res) => {
				wx.request({
					url: getApp().globalData.http1 + 'action=returnOrderDetail&thid=' + options.id + '&uid=' + res.data.uid,
					success: (e) => {
						console.log(e)
						if (e.data.data.Ttype == 1) {
							e.data.data.Ttype = "退货"
						} else if (e.data.data.Ttype == 2) {
							e.data.data.Ttype = "换货"
						} else {
							console.log(e.data.data.Ttype)
							e.data.data.Ttype = "仅退款"
						}
						this.setData({
							uid: res.data.uid,
							data: e.data.data
						})
					}
				})
			}
		})
	},
	no(e) {
		this.setData({
			state: e.currentTarget.dataset.id
		})
	},
	remake(e) {
		this.setData({
			remake: e.detail.value
		})
	},
	noSure(e) {
		// 参数名：action=returnOrderApp，
		// thid=退货ID，uid=用户ID，lx=1/2（同意/不同意）
		// ，yuanyin=拒绝原因，mobile=收货人电话，address=收货人地址
		// ，uname=收货人姓名，
		let a = ''
		if (e.currentTarget.dataset.id == 2) {
			a = 'action=returnOrderApp&yuanyin=' + this.data.remake
			if (this.data.remake != '') {
				wx.request({
					url: getApp().globalData.http1 + a + '&lx=2&mobile=' + this.data.data.mobile + '&address=' + this.data.data.address +
						'&uname=' + this.data.data.shouhuoren + '&thid=' + this.data.data.thid + '&uid=' + this.data.uid,
					success: (e) => {
						console.log(e)
						wx.navigateBack({
							delta: 1
						})
					}
				})
			}
		} else {
			if (this.data.data.Ttype == '仅退款') {
				a = 'action=returnOrderApp&yuanyin='
				wx.showModal({
					title: '是否确认退款？',
					success: (e) => {
						if (e.confirm) {
							wx.request({
								url: getApp().globalData.http1 + a + '&lx=1&mobile=' + this.data.mobile + '&address=' + this.data.address +
									'&uname=' + this.data.name + '&thid=' + this.data.data.thid + '&uid=' + this.data.uid,
								success: (e) => {
									console.log(e)
									wx.navigateBack({
										delta: 1
									})
								}
							})
						}
					}
				})
			} else {
				wx.navigateTo({
					url:'../map/map?thid='+this.data.data.thid
				})
			}
		}
	}
})
